package cn.school.mybatis.servlet;

import cn.school.mybatis.pojo.Result;
import cn.school.mybatis.service.ResultService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/doExamAddServlet")
public class ExamAddServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        String examDate = request.getParameter("examDate");
        System.out.println("examDate:"+examDate);
        int stID =0;
        int sbID=0;
        float score=0f;

        try{
             stID = new Integer(request.getParameter("stuID"));
            System.out.println("stID:"+stID);
        } catch (Exception e) {
            e.printStackTrace();
        }
        try{
             sbID = new Integer(request.getParameter("subID"));
            System.out.println("sbID:"+sbID);
        } catch (Exception e) {
            e.printStackTrace();
        }try{
             score  =new Float(request.getParameter("score"));
            System.out.println("score:"+score);
        } catch (Exception e) {
            e.printStackTrace();
        }

        Result exResult = new Result(examDate, score, stID, sbID);
        System.err.println("exResult:"+exResult);
        int result = 0;
        try {
            result = ResultService.RESULT_SERVICE.add(exResult);
        } catch (Exception e) {
        }
        response.getWriter().print(result > 0 ? true : false);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
